<?php

/**
 * Miscellanious helper class.
 *
 * @version  $Id: misc.php 2 2009-10-02 23:06:43Z perfilev $
 * @package  Application
 */

class Misc
{

	/**
	 * Returns size in KB, MB, GB...
	 *
	 * @param  integer  $size  Size in bytes.
	 * @return string
	 */
	public static function bytes($size)
	{
		$units = array('B', 'KB', 'MB' , 'GB', 'TB', 'PB');
		$u = 0;
		while ($size >= 1024) {
			$u++;
			$size = $size / 1024;
		}
		return number_format($size, $u ? 2 : 0) . $units[$u];
	}

}
